<?php

// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://demo.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库：https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------

namespace app\currency\controller;

use app\currency\service\ExtendService;
use library\Controller;

/**
 * 参数配置
 * Class Config
 * @package app\store\controller
 */
class Config extends Controller
{

    /**
     * 参数配置
     * @auth true
     * @menu true
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function index()
    {
        $this->title = '参数配置';
        $this->applyCsrfToken('save');
        $ExtendService = new ExtendService();
        $this->query = $ExtendService->querySmsBalance();
        $this->fetch();
    }

    /**
     * 保存商城参数
     * @auth true
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function save()
    {
        if ($this->request->isPost()) {
            $this->applyCsrfToken('save');
            $data = $this->request->post();
            if(isset($data['present_integral_ratio'])){
                if(!isset($data['present_integral_switch'])){
                    $data['present_integral_switch'] = '0';
                }
                if(!isset($data['invite_present_switch'])){
                    $data['invite_present_switch'] = '0';
                }
            }
            foreach ($data as $k => $v) sysconf($k, $v);
            $this->success('配置保存成功！');
        }
    }

    /**
     * @auth true
     */
    public function save_brief()
    {
        if($this->request->isPost()){
            $this->applyCsrfToken('save_brief');
            $data = $this->request->post();
            unset($data['_token_']);
            $data['value'] =$data[$data['name']];
            unset($data[$data['name']]);
            if(data_save('SystemBrief',$data,'name')){
             $this->success('配置更新成功');
            }else{
                $this->error('系统繁忙');
            }

        }
    }

}
